<template name="sendcar">
	<!-- 库存物资打印 -->
	<view class="mypage">
		<!-- <view class="cu-bar search bg-white">
      <view class="search-form round">
        <text class="cuIcon-search"></text>
        <input type="text" placeholder="请输入物资名称" v-model="keyword" />
        <input type="text" placeholder="请输入物资规格" v-model="keyword2" />
      </view>
      <view class="action">
        <button class="cu-btn bg-blue shadow-blur round" @tap="handelSearch">搜索</button>
      </view>
    </view> -->

		<view class="card-list-wrapper">
			<view class="card-list-row radius shadow-warp bg-white margin-top" v-for="(item,index) in planList"
				:key="index" >
				<!-- <view class="card-list-row-1 margin-top">
					<text class="cuIcon-title text-red"></text>
					<text>组织：{{ item.STORENAME || item.VNAME || '' }}</text>
				</view> -->
				<view class="card-list-row-1">
					<text class="cuIcon-title text-orange"></text>
					<text>仓库：{{ item.STORENAME || '' }}</text>
				</view>
				<view class="card-list-row-1" v-if="item.STATIONNAME">
					<text class="cuIcon-title text-orange"></text>
					<text>货位：{{ item.STATIONNAME || '' }}</text>
				</view>
				
				<view class="card-list-row-1">
					<text class="cuIcon-title text-orange"></text>
					<text>库存种类：{{ item.MATERIALCOUNT || '' }}</text>
				</view>
				
				<view class="card-list-row-1">
					<text class="cuIcon-title text-orange"></text>
					<text>库存量：{{ item.NNUM  }} </text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-orange"></text>
					<text>含税金额：{{ item.NORIGTAXMNY || '' }}</text>
				</view>

			<!-- 	<view class="flex-just-center top-border margin-top btn-wrap">
					<button class="cu-btn round lines-blue" @click="printQR(item)">打印</button>
				</view> -->

			</view>
		</view>

		<view class="scan-wrap" @click="openScanMater" v-if="!planList.length">
			<text class="cuIcon-scan text-xxl"></text>
			<view class="title">
				请扫码仓库或者货位二维码
			</view>
		</view>

		<modal title="高级查询" placeholder :isShow="isShowModal" @cancelModal="cancelModal" @okModal="okModal"></modal>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex";
	import api from "@/common/api.js";
	import utils from "@/common/util.js";
	import modal from "@/components/modal/modal_mater.vue";
	const plug = uni.requireNativePlugin('Html5app-Gprinter');
	let query = {
		category: "",
		page: 1,
		rows: "10",
		sidx: "CREATIONTIME",
		sord: "desc",
		queryJson: "",
		TYPE: "",
		userId: "",
		account: ""
	};
	let _self,
		menuType,
		page = 1,
		billID,
		total = 1,
		goPath = "",
		pageTitle = "基础物资列表(",
		queryJson = {};

	export default {
		computed: mapState(["userInfo", "baseUrl", "checkData"]),
		data() {
			return {
				planList: [],
				keyword: "",
				keyword2: "",
				category: "",
				isShowModal: false,
				config: {
					materId: "",
					materName: ""
				},
				scodeData:null 
			};
		},

		onLoad(p) {
			_self = this;
		},
		components: {
			modal
		},
		onNavigationBarButtonTap(e) {
			this.openScanMater()
		},
	
		
		methods: {

			// 扫描物资
			openScanMater() {
				let URL = api.apiPublic.ScanCode;
				this.$utils.Scan(URL, item => {
					// console.log(item);
					this.getList(item)
				});
			},

			openDetail(e) {
				_self.planList[e].ischeck = !_self.planList[e].ischeck;
				_self.planList[e].myIndex = e;
			},
			

			getList(queryData) {
				
				let URL = '/api/APPCommon//GetStoreStatistics';
				this.axios({
					url: URL,
					data: queryData,
					isLoading: 1
				}).then(res => {
					let {
						Result
					} = res;
					let a = Result.map(i=>{
						let c = {  ...queryData , ...i }
						return c ;
					})
					_self.planList = a 
					
				}).catch(Error=>{
					console.log(Error);
				})
				

			},
			setPageTitle(d) {
				uni.setNavigationBarTitle({
					title: d
				});
			},

			printQR(item) {
				let TNT = `TYPE:3|${item.PK_ORG}|${item.PK_STORE}|${item.PK_STATION}|${item.BARCODE}`;
				let qrcodeData = {
					name: item.MATERIALNAME,
					type: item.MATSPEC,
					bcode: item.BARCODE,
					qcode: TNT,
					number: 1
				}
				this.printerLable(qrcodeData)
				// console.log(qrcodeData);
			},

			// 打印标签
			printerLable(data) {
				plug.printer({
					"TSC": _self.$utils.LableSet(data)
				}, ret => {
					// _this.tip=JSON.stringify(ret);
					if (ret.state == 1) {
						_self.$utils.tips('打印失败！请检查蓝牙打印机状态')
					} else if (ret.state == 2) {
						_self.$utils.tips('已完成打印')
					}
					// console.log(JSON.stringify(ret));
				});
			},


			// 控制高级查询条件
			cancelModal() {
				this.isShowModal = false;
			},
			okModal(val) {
				this.cancelModal();
				queryJson = {
					...val
				};
				page = 1;
				total = 1;
				_self.planList = [];
				this.getList();
			}
		}
	};
</script>

<style>
	page {
		padding-bottom: 100rpx;
		box-sizing: border-box;
	}

	.card-list-wrapper {
		width: 710upx;
		margin: 0 auto;
	}

	.card-list-row {
		padding: 20upx;
	}

	.card-list-row-1 {
		padding: 10upx 0;
	}



	.top-border {
		border-top: 1upx solid rgba(0, 0, 0, 0.1);
	}

	.top-wrap {
		padding-bottom: 20upx;
	}

	.bottom-border {
		border-bottom: 1upx solid rgba(0, 0, 0, 0.1);
	}

	.btn-wrap {
		padding-top: 20upx;
	}

	.checkFlag {
		top: 50%;
		right: 20upx;
		font-size: 40upx;
	}

	.next-btn-wrap {
		position: fixed;
		right: 50upx;
		bottom: 100upx;
	}

	.big-btn {
		width: 100upx;
		height: 100upx;
		border-radius: 50upx;
		font-size: 40upx;
	}
	.scan-wrap{
		text-align: center;
		position: absolute;
		top: 40%;
		left: 50%;
		transform: translateX(-50%);
	}
	
	.scan-wrap .cuIcon-scan{
		font-size: 100rpx;
		color: #167ff1;
	}
</style>
